<?php
namespace app\home\controller;
use app\common\controller\Home;	
class Search extends Home{  
    public function index(){
		$Url = param_url();
		$mode= list_search(F('_data/modellist'),'id='.$Url['sid']);
		$JumpUrl = param_jump($Url);
		config('model',strtolower($this->request->module().'/'.$this->request->controller().'/'.$this->request->action()));
		config('currentpage',$Url['page']);
		config('params',array('wd'=>$Url['wd'],'p'=>"zanpianpage"));
		$channel = $this->Lable_Search($Url);
        $this->assign('param',$Url);
		$this->assign($channel);
		if (\think\Request::instance()->isAjax()&& !empty($Url['sid'])){
		$array_search['search_skin'] = 'search_'.$mode[0]['name'].'_ajax';	
		return view('/'.$array_search['search_skin']);
		}else{
		return view('/'.$channel['search_skin']);	
		}
    }
    // 联想搜索
    public function vod(){
		$wd = htmlspecialchars(input('q/s',''));
		$limit = !empty($Url['limit']) ? $Url['limit'] : '10';
		$where['vod_name|vod_letters'] = array('like',$wd.'%');
		$rs=\think\Db::name('vod');
        $data=$rs->field('vod_id,vod_cid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->select();
		$count = $rs->where($where)->count('vod_id');
		if($data){
			foreach($data as $key=>$val){
                $list['data'][$key]['vod_name'] = $val['vod_name'];
				$list['data'][$key]['vod_title'] = $val['vod_title'];
	            $list['data'][$key]['vod_url'] = zanpian_data_url('home/vod/read',array('id'=>$val['vod_id'],'pinyin'=>$val['vod_letters'],'cid'=>$val['vod_cid'],'dir'=>getlistname($val['vod_cid'],'list_dir'),'jumpurl'=>$val['vod_jumpurl']));
			}
			return json(['data'=>$list['data'],'info'=>'ok','status'=>1]);
		}else{
			return json(['data'=>$data,'info'=>'ok','status'=>0]);
			}
    }	
    // 联想搜索
    public function ajax(){
		$Url = param_url();
		$limit = !empty($Url['limit']) ? $Url['limit'] : '10';
		$where['vod_name|vod_letters'] = array('like',$Url['wd'].'%');
		$rs=\think\Db::name('vod');
        $data=$rs->field('vod_id,vod_cid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->select();
		$count = $rs->where($where)->count('vod_id');
		if($data){
			foreach($data as $key=>$val){
		     $data[$key]['list_id'] = $val['vod_cid'];
		     $data[$key]['list_name'] = getlistname($val['vod_cid'],'list_name');
		     $data[$key]['list_url'] = getlistname($val['vod_cid'],'list_url');
		     $data[$key]['vod_readurl'] = zanpian_data_url('home/vod/read',array('id'=>$val['vod_id'],'pinyin'=>$val['vod_letters'],'cid'=>$val['vod_cid'],'dir'=>getlistname($val['vod_cid'],'list_dir'),'jumpurl'=>$val['vod_jumpurl']));
		     $data[$key]['vod_picurl'] = zanpian_img_url($val['vod_pic']);
			}
			return jsonp($data);
		}
    }
	// 联想搜索
    public function s(){
		$wd = htmlspecialchars(input('q/s',''));
		$limit = !empty($Url['limit']) ? $Url['limit'] : '10';
		$where['vod_name|vod_letters'] = array('like','%'.$wd.'%');
		$rs=\think\Db::name('vod');
        $data=$rs->field('vod_id,vod_cid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->cache(600)->select();
        // $list = Db::name('vod')->field('vod_id,vod_cid,vod_letters,vod_name,vod_jumpurl')->where($where)->limit(1)->order('vod_addtime desc')->cache(600)->find();
		$count = $rs->where($where)->count('vod_id');
		if($data){
			foreach($data as $key=>$val){
                $list['data'][$key]['name'] = $val['vod_name'];
				$list['data'][$key]['title'] = $val['vod_title'];
				$list['data'][$key]['year'] = $val['vod_year'];
				if(!strstr($val['vod_pic'],'://')){
					$val['vod_pic'] = config('upload_http_prefix').$val['vod_pic'];
				}
				$list['data'][$key]['pic'] = $val['vod_pic'];
				$list['data'][$key]['gold'] = $val['vod_gold'];
				if(is_numeric($val['vod_continu'])) {
					if($val['vod_continu'] > 0) {
						$val['vod_continu'] = '连载至'.$val['vod_continu'].'话';
					} else {
						$val['vod_continu'] = '完结';
					}
				} else {
					$val['vod_continu'] = $val['vod_title'];
				}
				$list['data'][$key]['continu'] = $val['vod_continu'];
				$list['data'][$key]['type'] = getlistname($val['vod_cid'], 'list_name');
	            $list['data'][$key]['url'] = zanpian_data_url('home/vod/read',array('id'=>$val['vod_id'],'pinyin'=>$val['vod_letters'],'cid'=>$val['vod_cid'],'dir'=>getlistname($val['vod_cid'],'list_dir'),'jumpurl'=>$val['vod_jumpurl']));
			}
			return json(['data'=>$list['data'],'info'=>'ok','status'=>1]);
		}else{
			return json(['data'=>$data,'info'=>'ok','status'=>0]);
		}
    }
	// 弹出信息层
    public function pop(){
		$wd = htmlspecialchars(input('q/s',''));
		$limit = !empty($Url['limit']) ? $Url['limit'] : '1';
		$where['vod_id'] = array('like',$wd);
		$rs=\think\Db::name('vod');
        $data=$rs->field('vod_id,vod_cid,vod_mcid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->cache(600)->select();
		$count = $rs->where($where)->count('vod_id');
		if($data){
			foreach($data as $key=>$val){
				$list['data'][$key]['id'] = $val['vod_id'];
				$list['data'][$key]['cid'] = $val['vod_cid'];
                $list['data'][$key]['name'] = $val['vod_name'];
				$list['data'][$key]['year'] = $val['vod_year'];
				$list['data'][$key]['mcid'] = mcat_url($val['vod_mcid'],$val['vod_cid']);
				$list['data'][$key]['area'] = "<a target='_blank' href='".zanpian_type_url('home/vod/type',array('id'=>3,'dir'=>getlistdir(3),'mcid'=>"",'area'=>urlencode($val['vod_area']),'year'=>"",'letter'=>"",'order'=>""))."'>".$val['vod_area']."</a>";
				$list['data'][$key]['list_name'] = getlistname($val['vod_cid'],'list_name');
				$list['data'][$key]['list_url'] = getlistname($val['vod_cid'],'list_url');
				$list['data'][$key]['time'] = zanpian_from_time($val['vod_addtime']);
				$list['data'][$key]['actor'] = get_star_url(str_ireplace(array('未知','未录入'),'',$val['vod_actor']),'no',3);
				$list['data'][$key]['director'] = get_star_url(str_ireplace(array('未知','未录入'),'',$val['vod_director']),'no',1);
				$list['data'][$key]['gold'] = $val['vod_gold'];
				$list['data'][$key]['content'] = msubstr($val['vod_content'],0,120,h);
	            $list['data'][$key]['url'] = zanpian_data_url('home/vod/read',array('id'=>$val['vod_id'],'pinyin'=>$val['vod_letters'],'cid'=>$val['vod_cid'],'dir'=>getlistname($val['vod_cid'],'list_dir'),'jumpurl'=>$val['vod_jumpurl']));
			}
			return json(['data'=>$list['data'],'info'=>'ok','status'=>1]);
		}else{
			return json(['data'=>$data,'info'=>'ok','status'=>0]);
		}
    }
	// 弹出信息层
    public function xcxdetail(){
		$wd = htmlspecialchars(input('q/s',''));
		$limit = !empty($Url['limit']) ? $Url['limit'] : '1';
		$where['vod_id'] = $wd;
		$rs=\think\Db::name('vod');
        $data=$rs->field('vod_id,vod_cid,vod_mcid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->cache(600)->select();
		$count = $rs->where($where)->count('vod_id');
		if($data){
			foreach($data as $key=>$val){
				$list['data'][$key]['type'] = getlistname($val['vod_cid'],'list_name');
				$list['data'][$key]['mcid'] = mcat_name($val['vod_mcid'],$val['vod_cid']);
				$list['data'][$key]['id'] = $val['vod_id'];
				$list['data'][$key]['cid'] = $val['vod_cid'];
                $list['data'][$key]['name'] = $val['vod_name'];
				$list['data'][$key]['area'] = $val['vod_area'];
				$list['data'][$key]['year'] = $val['vod_year'];
				if(!strstr($val['vod_pic'],'://')){
					$val['vod_pic'] = config('upload_http_prefix').$val['vod_pic'];
				}
				$list['data'][$key]['pic'] = $val['vod_pic'];
				if(is_numeric($val['vod_continu'])) {
					if($val['vod_continu'] > 0) {
						$val['vod_continu'] = '连载至'.$val['vod_continu'].'话';
					} else {
						$val['vod_continu'] = '完结';
					}
				} else {
					$val['vod_continu'] = $val['vod_title'];
				}
				$list['data'][$key]['continu'] = $val['vod_continu'];
				$list['data'][$key]['time'] = zanpian_from_time($val['vod_addtime']);
				$list['data'][$key]['actor'] = str_ireplace(array('未知','未录入'),'',$val['vod_actor']);
				$list['data'][$key]['director'] = str_ireplace(array('未知','未录入'),'',$val['vod_director']);
				$list['data'][$key]['gold'] = $val['vod_gold'];
				$list['data'][$key]['content'] = msubstr($val['vod_content'],0,120,h);
			}
			return json(['data'=>$list['data'],'info'=>'ok','status'=>1]);
		}else{
			return json(['data'=>$data,'info'=>'ok','status'=>0]);
		}
    }
}
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
